import 'package:common_utils/common_utils.dart';
import 'package:erp/res/colors.dart';
import 'package:erp/util/number_textinput_formatter.dart';
import 'package:erp/widgets/form1/form_builder.dart';
import 'package:erp/widgets/my_app_bar.dart';
import 'package:erp/widgets/my_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'controller.dart';

export 'binding.dart';

class SaleProjectDescription extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var controller = Get.find<SaleProjectDescriptionController>();
    var buttonGroup;
    if (!controller.readOnly) {
      buttonGroup = Container(
        padding: EdgeInsets.only(top: 60.h),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            MyButton(
              backgroundColor: Colors.white,
              textColor: Colors.black,
              text: "取消",
              fontSize: 24.sp,
              onPressed: () {
                controller.cancel();
              },
              minWidth: 100.w,
              minHeight: 50.h,
              side: BorderSide(color: Color(0xFF4C88FF), width: 1.w),
              radius: 4.r,
            ),
            SizedBox(width: 40.w),
            MyButton(
              backgroundColor: Color(0xFF4C88FF),
              text: "保存",
              fontSize: 24.sp,
              onPressed: () {
                controller.save();
              },
              minWidth: 100.w,
              minHeight: 50.h,
              radius: 4.r,
            ),
          ],
        ),
      );
    } else {
      buttonGroup = SizedBox.shrink();
    }

    return Scaffold(
      backgroundColor: Colours.bg_color,
      appBar: MyAppBar(
        centerTitle: '项目详细情况',
        titleColor: Colors.black,
        onPressed: () {},
      ),
      body: Container(
        width: MediaQuery.of(context).size.width,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: EdgeInsets.only(left: 51.w, top: 30.h, bottom: 31.h),
              child: Text(
                "添加项目情况说明",
                style: TextStyle(
                  color: Color(0xFF333333),
                  fontSize: 30.sp,
                  fontWeight: FontWeight.w400,
                ),
              ),
            ),
            Container(
              padding: EdgeInsets.only(left: 52.w, right: 52.w, bottom: 30.h),
              color: Colors.white,
              child: FormBuilder(
                readOnly: controller.readOnly,
                formManagement: controller.formManagement,
                initialValue: controller.formData,
                children: [
                  ClearableTextFormField(
                    label: '* 项目内容',
                    name: 'detailContent',
                    validator: (value) {
                      if (ObjectUtil.isEmpty(value)) {
                        return "项目内容不能为空";
                      }
                    },
                  ),
                  ClearableTextFormField(
                    label: '* 预估合同金额',
                    placeholder: '元',
                    name: 'detailAmount',
                    inputFormatters: [XNumberTextInputFormatter(maxDecimalLength: 2, maxIntegerLength: 9)],
                    validator: (value) {
                      if (ObjectUtil.isEmpty(value) && (value as double) > 0) {
                        return "预估合同金额不能为空";
                      }
                    },
                  ),
                  ClearableTextFormField(
                    label: '* 业务主管',
                    name: 'detailOwner',
                    validator: (value) {
                      if (ObjectUtil.isEmpty(value)) {
                        return "业务主管不能为空";
                      }
                    },
                  ),
                  ClearableTextareaFormField(
                    label: '* 备注内容',
                    name: 'detailMemo',
                    validator: (value) {
                      if (ObjectUtil.isEmpty(value)) {
                        return "备注内容不能为空";
                      }
                    },
                  ),
                ],
              ),
            ),
            buttonGroup
          ],
        ),
      ),
    );
  }
}
